# -*- coding: UTF-8 -*-
import time
from datetime import datetime, timedelta
from datetime import timezone

if __name__ == '__main__':

    window_size = 60

    f = open('gen_block_feature_%d.sh' % window_size, 'w')
    f.write("#!/bin/bash")
    f.write("\n")
    f.write("\n")

    run_templete_str = "python ./BlockFeatureGen.py \"%s\" \"%s\" %d %d >block_%d_logs/GenBlock_%d_%d.log " \
                       " 2>block_%d_error_logs/GenBlock_error_%d_%d.log &"

    begin_time_str = "2018-12-07 00:00:00"
    end_time_str = "2019-03-06 23:59:00"
    begin_time = datetime.strptime(begin_time_str, "%Y-%m-%d %H:%M:%S")
    end_time = datetime.strptime(end_time_str, "%Y-%m-%d %H:%M:%S")

    iter_time = begin_time
    count = 0
    while iter_time < end_time:
        step_hours = 12 * 4
        step_minutes = step_hours * 60 - 1
        iter_time_end = iter_time + timedelta(minutes=step_minutes)
        s = run_templete_str % (
            iter_time, iter_time_end, window_size, count, window_size, window_size, count, window_size, window_size,
            count)
        print(s)
        f.write(s + "\n")
        iter_time = iter_time + timedelta(hours=step_hours)
        count += 1
    f.close()
    print(count)
